/*
 * @lc app=leetcode.cn id=645 lang=typescript
 *
 * [645] 错误的集合
 */

// @lc code=start
function findErrorNums(nums: number[]): number[] {
    const set = new Set<number>();
    let repeat = NaN;
    nums.forEach((i) => {
        if (set.has(i)) {
            repeat = i;
        } else {
            set.add(i);
        }
    });
    for (let i = 0; i < nums.length; i++) {
        if (!set.has(i + 1)) return [repeat, i + 1];
    }
    throw new Error("错误");
}
// @lc code=end
